//思路：利用总和减去前面和得到后面和解决时间复杂度,并累加化为一层循环降低复杂度,注意数据相乘相加类型为long

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        long [] nums=new long[n];
        long sum=0;
        long  min=Long.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            nums[i]=in.nextInt();
            sum+=nums[i];
        }
        long sum1=0l,sum2=0l;
        for (int i = 0; i < nums.length-1; i++) {
            sum1+=nums[i];
            sum2=sum-sum1;

            min=Math.min(min,sum1*sum2);
        }
        System.out.println(min);
    }

}













